package mobi.hami.huapin.service.impl;

import mobi.hami.huapin.dao.UserPresentSkuMapper;
import mobi.hami.huapin.model.UserPresentSku;
import mobi.hami.huapin.service.UserPresentSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Create by 小峰 on 2018/9/26.
 */
@Service
public class UserPresentSkuServiceImpl implements UserPresentSkuService {

    @Autowired
    private UserPresentSkuMapper userPresentSkuMapper;

    @Override
    public List<UserPresentSku> getUserPresentCount(Integer userId) {
        return userPresentSkuMapper.getUserPresentCount(userId);
    }

    /**
     * 增加一条赠送商品的记录
     * @return
     */
    public Integer saveUserPresentSkuByModel(Integer userId,Integer huapinId, Integer orderId,Integer skuId){
        UserPresentSku userPresentSku= new UserPresentSku();
        userPresentSku.setHuapin_id(huapinId);
        userPresentSku.setUser_id(userId);
        userPresentSku.setOrder_id(orderId);
        userPresentSku.setSku_id(skuId);
        return userPresentSkuMapper.saveUserPresentSkuByModel(userPresentSku);
    }

    /**
     * 查询该用户在该拼团下是否已经送过赠品
     * @param huapinId
     * @param userId
     * @return true :送过,false:未送过
     */
    public Boolean getCountByUserAndHuapin(Integer huapinId,Integer userId){
        return  userPresentSkuMapper.getCountByUserAndHuapin(huapinId,userId)>0;
    }
}
